package tasoloikka;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

public class Gun {
  
  private int positionX;
  private int positionY;
  private int height = 4;
  private int width = 18;
  private int playerWidth = 8;
  private int playerHeight = 16;
  private double aimAngle;
  private int screenHeight;
  private int screenWidth;

  
  public Gun(int screenWidth, int screenHeight) {
    this.screenHeight = screenHeight;
    this.screenWidth = screenWidth;
    
    this.playerHeight = 16;
    this.playerWidth = 8;
  }
  
  public void paint(Graphics gbi) {
    Graphics2D g2d = (Graphics2D) gbi;
    
    g2d.translate(positionX+(playerWidth), positionY+(playerHeight));
    g2d.rotate(aimAngle);
    
    g2d.setColor(Color.white);
    g2d.drawRect(-width+4, -height/2, width, height);
    g2d.drawRect(-width+4, -height/2, 4, 6);
    
    g2d.rotate(-aimAngle);
    g2d.translate(-positionX-(playerWidth), -positionY-(playerHeight));
  }
  
  
  public void calculateAim(int mouseX, int mouseY){
    aimAngle = Math.atan2(positionY-mouseY,positionX-mouseX);
  }
  
  public void setPositionX(int x) {
    positionX = x;
  }
  
  public void setPositionY(int y) {
    positionY = y;
  }
}
